package com.weixing.mall.provider.controller.pdm;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.core.support.auth.SysAuth;
import com.weixing.mall.core.support.auth.SysInfo;
import com.weixing.mall.provider.model.dto.pdm.ProductDevelopDto;
import com.weixing.mall.provider.model.query.ProductDevelopQuery;
import com.weixing.mall.provider.service.IProductDevelopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ProjectController
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/9/10
 * @Version 1.0
 **/
@RestController
@RequestMapping("project")
@Api(value = "产品研发基本信息APi", tags = "产品研发基本信息")
public class ProductDevelopController extends BaseController {

    @Autowired
    private IProductDevelopService productDevelopService;

    @ApiOperation(value = "加载产品研发基本信息列表")
    @GetMapping("")
    public Result list(ProductDevelopQuery productDevelopQuery) {
        return ResultUtil.success(productDevelopService.selectListOfPage(initMpPage(), productDevelopQuery));
    }

    @ApiOperation(value = "通过id查产品研发基本信息")
    @GetMapping("{id}")
    public Result getProductDevelopById(@PathVariable Long id) {
        return ResultUtil.success(productDevelopService.getProductDevelopById(id));
    }

    @ApiOperation(value = "保存产品研发基本信息")
    @PostMapping("save")
    @NoRepeatSubmit
    public Result save(@SysInfo SysAuth auth, @Validated ProductDevelopDto productDevelopDto) {
        productDevelopService.save(productDevelopDto,auth.getUid());
        return ResultUtil.success();
    }

    @ApiOperation(value ="研发流程信息查看")
    @GetMapping("selectFlowList")
    public Result selectFlowList(ProductDevelopQuery productDevelopQuery){
        return  ResultUtil.success(productDevelopService.selectFlowList(initMpPage(),productDevelopQuery));
    }
    @ApiOperation(value = "删除产品研发信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "产品信息id", paramType = "path", dataType = "long")
    })
    @PostMapping("del/{id}")
    public Result del(@PathVariable long id) {
        return productDevelopService.removeById(id) ? ResultUtil.success() : ResultUtil.error();
    }
}
